package cn.wolfcode.web.controller;


import cn.wolfcode.domain.Exam;
import cn.wolfcode.domain.Question;
import cn.wolfcode.service.IExamService;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.qo.JsonResult;
import cn.wolfcode.service.IQuestionService;
import cn.wolfcode.util.RequiredPermission;
import com.github.pagehelper.PageInfo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/exam")
public class ExamController {

    @Autowired
    private IExamService examService;
    @Autowired
    private IQuestionService questionService;

    @RequiredPermission(name = "试卷生成页面", expression = "exam:input")
    @RequestMapping("/input")
    public String exam(Model model) {
        return "exam/input";
    }


    @RequestMapping("/question")
    @RequiredPermission(name = "试题页面", expression = "exam:question")
    public String question(Model model, Exam exam) {
        //保存了考试表 和考试表对应的题目(中间表)
        Map<String, List<Question>> stringListMap = examService.saveExam(exam);
        //共享第一个页面传过来的数据 把标题 分数 时间都显示了
        model.addAttribute("exam", exam);


        //发送sql 获取单选题目
        List<Question> oneQuestions = stringListMap.get("oneQuestions");
        model.addAttribute("oneQuestions", oneQuestions);
        //获取多选题目
        List<Question> manyQuestions = stringListMap.get("manyQuestions");
        model.addAttribute("manyQuestions", manyQuestions);
        //获取判断题目
        List<Question> judgeQuestions = stringListMap.get("judgeQuestions");
        model.addAttribute("judgeQuestions", judgeQuestions);
        return "exam/exam";
    }
}




//客户做题

//每一个题目下面都有4个单选框给客户选择 多选是复选框 两个单选框是判断
//客户点击提交 计算客户的分数 和 错题
//单选
//0 1 2 3
//D A B C
//拿到题目的id 找到对应的正确答案 如果求余的值 和 客户选的id 值一致 就是对的
//定义一个map id 是题目id
